package com.xunlai.infra.permission.common.vo;

import com.xunlai.infra.permission.common.exception.ExceptionCodeEnum;

/**
 * @author liang
 * @date 2022/12/2 17:40
 */
public record BaseResponse<T>(
        Integer code,
        T data,
        String msg
) {
    public static <T> BaseResponse<T> success(T data, String msg){
        return new BaseResponse<>(ExceptionCodeEnum.SUCCESS.getCode(),data,msg);
    }

    public static <T> BaseResponse<T> success(){
        return new BaseResponse<>(ExceptionCodeEnum.SUCCESS.getCode(),null,"SUCCESS");
    }
    public static <T> BaseResponse<T> success(T data){
        return new BaseResponse<>(ExceptionCodeEnum.SUCCESS.getCode(),data,"SUCCESS");
    }
    public static <T> BaseResponse<T> error(Integer code, String msg){
        return new BaseResponse<>(code,null,msg);
    }
    public static <T> BaseResponse<T> error(Integer code, T data, String msg){
        return new BaseResponse<>(code,data,msg);
    }

    public static <T> BaseResponse<T> error(ExceptionCodeEnum codeEnum){
        return new BaseResponse<>(codeEnum.getCode(),null,codeEnum.getDesc());
    }

    public static <T> BaseResponse<T> error(ExceptionCodeEnum codeEnum, T data){
        return new BaseResponse<>(codeEnum.getCode(),data,codeEnum.getDesc());
    }
}
